namespace MxWeiXinPF.WeiXinComm
{
    using MxWeiXinPF.DBUtility;
    using MxWeiXinPF.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;

    public class wxResponseBaseMgr
    {
        public static int Add(MxWeiXinPF.Model.wx_response_BaseData model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into wx_response_BaseData(");
            builder.Append("wid,wx_openid,requestType,requestContent,responseType,reponseContent,createTime,wx_xmlContent,createDate,flag,rType,remark,extInt,extStr,extStr2,extStr3)");
            builder.Append(" values (");
            builder.Append("@wid,@wx_openid,@requestType,@requestContent,@responseType,@reponseContent,@createTime,@wx_xmlContent,@createDate,@flag,@rType,@remark,@extInt,@extStr,@extStr2,@extStr3)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@wx_openid", SqlDbType.VarChar, 100), new SqlParameter("@requestType", SqlDbType.VarChar, 50), new SqlParameter("@requestContent", SqlDbType.VarChar, 0x7d0), new SqlParameter("@responseType", SqlDbType.VarChar, 50), new SqlParameter("@reponseContent", SqlDbType.VarChar, 0x7d0), new SqlParameter("@createTime", SqlDbType.VarChar, 40), new SqlParameter("@wx_xmlContent", SqlDbType.VarChar, 0x7d0), new SqlParameter("@createDate", SqlDbType.DateTime), new SqlParameter("@flag", SqlDbType.Int, 4), new SqlParameter("@rType", SqlDbType.VarChar, 70), new SqlParameter("@remark", SqlDbType.VarChar, 500), new SqlParameter("@extInt", SqlDbType.Int, 4), new SqlParameter("@extStr", SqlDbType.VarChar, 200), new SqlParameter("@extStr2", SqlDbType.VarChar, 700), new SqlParameter("@extStr3", SqlDbType.VarChar, 0x7d0) };
            cmdParms[0].Value = model.wid;
            cmdParms[1].Value = model.wx_openid;
            cmdParms[2].Value = model.requestType;
            cmdParms[3].Value = model.requestContent;
            cmdParms[4].Value = model.responseType;
            cmdParms[5].Value = model.reponseContent;
            cmdParms[6].Value = model.createTime;
            cmdParms[7].Value = model.wx_xmlContent;
            cmdParms[8].Value = model.createDate;
            cmdParms[9].Value = model.flag;
            cmdParms[10].Value = model.rType;
            cmdParms[11].Value = model.remark;
            cmdParms[12].Value = model.extInt;
            cmdParms[13].Value = model.extStr;
            cmdParms[14].Value = model.extStr2;
            cmdParms[15].Value = model.extStr3;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public static int Add(int wid, string openid, string requestType, string requestContent, string responseType, string responseContent, string ToUserName)
        {
            try
            {
                MxWeiXinPF.Model.wx_response_BaseData model = new MxWeiXinPF.Model.wx_response_BaseData {
                    wid = new int?(wid),
                    wx_openid = openid,
                    requestType = requestType,
                    requestContent = requestContent,
                    responseType = responseType,
                    reponseContent = responseContent,
                    wx_xmlContent = ToUserName,
                    createDate = new DateTime?(DateTime.Now)
                };
                return Add(model);
            }
            catch (Exception)
            {
                return 0;
            }
        }
    }
}

